#include "atmdata_average.h"

AtmData_Average::AtmData_Average(QObject *parent) : QObject(parent)
{
    counter_inMinutes = 0;
    counter_inHours = 0;
    Data_minAvg.set_size(3);
    Data_hourAvg.set_size(3);
}

bool AtmData_Average::isMinuteDataAvailable()
{
    return counter_inMinutes > 0;
}

bool AtmData_Average::isHourDataAvailable()
{
    return counter_inHours > 0;
}

Col<double> AtmData_Average::getMinuteAvgData()
{
    if (counter_inMinutes > 0)
        Data_minAvg = mean(Data1_sec, 1);
    else
    {
        Data_minAvg.ones();
        Data_minAvg = Data_hourAvg * (-999);
    }
    Data1_sec.clear();
    counter_inMinutes = 0;
    return Data_minAvg;
}

Col<double> AtmData_Average::getHourAvgData()
{
    if (counter_inHours > 0)
        Data_hourAvg = mean(Data2_sec, 1);
    else
    {
        Data_hourAvg.ones();
        Data_hourAvg = Data_hourAvg * (-999);
    }
    Data2_sec.clear();
    counter_inHours = 0;
    return Data_hourAvg;
}

void AtmData_Average::add_atm_data(double T, double H, double P)
{
    Col <double> Combination(3);
    Combination(0) = T;
    Combination(1) = H;
    Combination(2) = P;

    Data1_sec.insert_cols(counter_inMinutes, Combination);
    Data2_sec.insert_cols(counter_inHours, Combination);

    counter_inMinutes++;
    counter_inHours++;
}

void AtmData_Average::init()
{
    counter_inMinutes = 0;
    counter_inHours = 0;

    Data1_sec.clear();
    Data2_sec.clear();
}
